<?php
namespace app\admin\controller;

use app\common\model\ChatMsgPrivate as ChatMsgPrivateModel;
use app\service\TouristService;

class Tourist extends Base
{
    /**
     * 列表
     * @return \think\response\Json
     */
    public function tourist_list()
    {
        if (request()->isPost()) {
            $data = input('');
            $page = input('page', 1);
            $size = input('size', 20);
            $where = [];
            if ($data['name']) {
                $where['name'] = ['like', "%{$data['name']}%"];
            }
            $list = TouristService::S()->queryPage($where, $page, $size);
            $total = TouristService::S()->queryCount($where);
            return returnJson(200,'',compact('page','size','list','total'));
        }
    }

    /**
     * 编辑添加
     * @return \think\response\Json
     */
    public function tourist_edit()
    {
        if(request()->isPost()){
            $data = input('');
            if(!$data['id']){
                return returnJson(202,'记录不存在');
            }
            $save_data = [
                'is_examine' => $data['is_examine'],
                'update_time'=>time(),
            ];
            if($data['id']){
                $where = [
                    'id'=>$data['id']
                ];
                $res = TouristService::S()->querySave($save_data,$where);
            }else{
                $save_data['create_time'] = time();
                $res = TouristService::S()->querySave($save_data);
            }
            if($res){
                return returnJson(200,'审核通过');
            }else{
                return returnJson(202,'审核不通过');
            }
        }
    }


    /**
     * @return \think\response\Json
     */
    public function del_tourist () {
        $input = input();
        if(!$input['id']) {
            return returnJson(1,'error');
        }
        \app\common\model\UserTourist::destroy(['id'=>$input['id']]);
        return returnJson(0,'删除成功');
    }


}

